#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

const int N = 100010, MOD = 1e9 + 7;

int n, m;
struct Seg
{
    int l, r;
    bool operator< (const Seg& t) const
    {
        return r < t.r;
    }
}w[N];
int s[N], f[N];

int get_l(int x)
{
    int l = 1, r = m + 1;
    while (l < r)
    {
        int mid = l + r >> 1;
        if (w[mid].r >= x) r = mid;
        else l = mid + 1;
    }
    return r;
}

int get_r(int x)
{
    int l = 1, r = m + 1;
    while (l < r)
    {
        int mid = l + r + 1 >> 1;
        if (w[mid].r <= x) l = mid;
        else r = mid - 1;
    }
    return r;
}

int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 2; i <= m + 1; i ++ ) scanf("%d%d", &w[i].l, &w[i].r);
    sort(w + 1, w + m + 2);

    int res = 0;
    f[1] = 1, s[1] = 1;
    for (int i = 2; i <= m + 1; i ++ )
    {
        int l = get_l(w[i].l);
        int r = get_r(w[i].r - 1);
        s[i] = s[i - 1];
        f[i] = (s[r] - s[l - 1]) % MOD;
        s[i] = (s[i - 1] + f[i]) % MOD;

        if (w[i].r == n) res = (res + f[i]) % MOD;
    }

    printf("%d\n", (res + MOD) % MOD);
    return 0;
}